<script setup>
import {ref} from 'vue'

const file = ref()

function init(event){
  file.value = new FormData()
  for(let f of event.target.files){
    file.value.append('fs',f)
  }
}

async function upfile(){


  file.value.append('name','李四')
  file.value.append('age',18)

  console.log(file.value)
  const data = await fetch('/uploads', {
    method: 'POST',
    body: file.value,
    headers: {
      token: '13014577033'
    }
  }).then(res => res.json()).then(data => {
    console.log(data)
  }).catch(err => {
    console.log("请求错误")
  })

  file.value = new FormData()
}


</script>

<template>
  <label>单文件:<input type="file" @change="init"></label>&nbsp; <button @click="upfile">upload file</button>
  <br><br><br>
  <label>多文件:<input type="file" @change="init" multiple></label>&nbsp; <button @click="upfile">upload files</button>
</template>

<style>
</style>
